Home > Java Programming > Language Fundamentals > Questions and Answers
01. |
1. What will be the output of the program? public class CommandArgs { public static void main(String [] args) { String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); } } and the command-line invocation is > java CommandArgs 1 2 3 4 | |||||||||||
|
02. |
What will be the output of the program? public class TestDogs { public static void main(String [] args) { Dog [][] theDogs = new Dog[3][]; System.out.println(theDogs[2][0].toString()); } } class Dog { } | |||||||||||
|
03. |
What will be the output of the program? public class X { public static void main(String [] args) { String names [] = new String[5]; for (int x=0; x < args.length; x++) names[x] = args[x]; System.out.println(names[2]); } } and the command line invocation is > java X a b | |||||||||||
|
04. | Which one of these lists contains only Java programming language keywords? | |||||||||||||||
|
05. | Which is a valid keyword in java? | |||||||||||
|
06. |
You have the following code in a file called Test.java class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} What will happen if you try to compile and run this? | |||||||||||
|
07. |
What is the result of trying to compile and run the following code. public final static void main(String[] args){ double d = 10.0 / -0; if(d == Double.POSITIVE_INFINITY) System.out.println("Positive infinity"); else System.out.println("Negative infinity"); } | |||||||||||
|
08. |
What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); } | |||||||||||||||
|
09. |
Which of the following are valid declarations? Note : None of the literals used here contain the character O they are all zeroes. 1. int i = 0XCAFE; 2. boolean b = 0; 3. char c = 'A'; 4. byte b = 128; 5. char c = "A"; | |||||||||||||||
|
10. |
What is the result of trying to compile and run this program. public class Test{ public static void main(String[] args){ int[] a = {1}; Test t = new Test(); t.increment(a); System.out.println(a[a.length - 1]); } void increment(int[] i){ i[i.length - 1]++; } } | |||||||||||
|